--- @param extension Package
--- @param HY HY_Utility
--- @param U Utility
return function(extension, HY, U)
    local hy_merlin_prismriver = General:new(extension, "hy_merlin_prismriver", "jin_k", 4, 4, General.Female)

    local reverberation = fk.CreateSkill {
        name = "reverberation",
    }
    reverberation:addEffect(fk.Damaged, {
        can_refresh = function(self, event, target, player, data)
            return player:hasSkill(reverberation.name, true) and data.card and data.from == player and not table.contains(player:getTableMark("reverberation_prohibit"), data.card.name)
        end,
        on_refresh = function(self, event, target, player, data)
            local room = player.room
            local records = player:getTableMark("reverberation")
            table.insertIfNeed(records, data.card.name)
            room:setPlayerMark(player, "reverberation", records)
        end,
    })
    reverberation:addAcquireEffect(function(self, player, is_start)
        local room = player.room
        local records = player:getTableMark("reverberation")
        local events = room.logic:getEventsOfScope(GameEvent.Damage, 999, function(e)
            return e.data.damage > 0 and e.data.card and e.data.from == player and not table.contains(player:getTableMark("reverberation_prohibit"), e.data.card.name)
        end, Player.HistoryRound)
        for _, e in ipairs(events) do
            table.insertIfNeed(records, e.data.card.name)
        end
        room:setPlayerMark(player, "reverberation", records)
    end)
    reverberation:addEffect(fk.RoundStart, {
        late_refresh = true,
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(reverberation.name) and #player:getTableMark("reverberation") > 0
        end,
        on_cost = function(self, event, target, player, data)
            local room = player.room
            local cards = {}
            for _, name in ipairs(player:getTableMark("reverberation")) do
                local card = Fk:cloneCard(name)
                if player:canUse(card, { bypass_times = true }) and table.any(room:getAlivePlayers(), function(t)
                        return player:canUseTo(card, t, { bypass_times = true }) or false
                    end) then
                    table.insertIfNeed(cards, name)
                end
            end
            local result = room:askToUseVirtualCard(player, {
                name = cards,
                skill_name = reverberation.name,
                prompt = "reverberation_prompt",
                skip = true,
                extra_data = {
                    bypass_times = true,
                }
            })
            if result then
                for _, name in ipairs(cards) do
                    if Fk:cloneCard(name).type == Fk:cloneCard(result.card.name).type then
                        table.removeOne(cards, name)
                    end
                end
                event:setCostData(self, { result, cards })
                return true
            end
        end,
        on_use = function(self, event, target, player, data)
            local room = player.room
            local result = event:getCostData(self)[1]
            local cards = event:getCostData(self)[2]
            local records = player:getTableMark("reverberation_prohibit")
            if result.card.multiple_targets then
                table.insertIfNeed(records, result.card.name)
            end
            room:setCardMark(result.card, "reverberation", 1)
            room:useCard(result)
            result = room:askToUseVirtualCard(player, {
                name = cards,
                skill_name = reverberation.name,
                prompt = "reverberation_prompt",
                extra_data = {
                    bypass_times = true,
                },
                skip = true,
            })
            if result then
                if result.card.multiple_targets then
                    table.insertIfNeed(records, result.card.name)
                end
                room:setCardMark(result.card, "reverberation", 1)
                room:useCard(result)
            end
            room:setPlayerMark(player, "reverberation_prohibit", records)
        end,
        can_refresh = function(self, event, target, player, data)
            return #player:getTableMark("reverberation") > 0
        end,
        on_refresh = function(self, event, target, player, data)
            player.room:setPlayerMark(player, "reverberation", 0)
        end,
    })
    reverberation:addEffect(fk.PreDamage, {
        is_delay_effect = true,
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(reverberation.name, true, true) and data.card and data.card:getMark("reverberation") ~= 0
        end,
        on_use = function(self, event, target, player, data)
            player.room:loseHp(data.to, data.damage, reverberation.name)
            data:preventDamage()
        end,
    })

    local soul_shock = fk.CreateSkill {
        name = "soul_shock",
    }
    soul_shock:addEffect("viewas", {
        card_filter = function(self, player, to_select, selected, selected_targets)
            local card = Fk:getCardById(to_select)
            if card.trueName ~= "slash" and card.type ~= Card.TypeTrick then
                return false
            end
            if table.contains(player:getTableMark("soul_shock-phase"), "1") and card.trueName == "slash" then
                return false
            end
            if table.contains(player:getTableMark("soul_shock-phase"), "2") and card.type == Card.TypeTrick then
                return false
            end
            return #selected < 1
        end,
        interaction = function(self, player)
            local names = {}
            for _, name in ipairs(Fk:getAllCardNames("bt", true, false)) do
                local card = Fk:cloneCard(name)
                if not card.is_damage_card or card.multiple_targets then
                    goto continue
                elseif table.contains(player:getTableMark("soul_shock-phase"), "1") and card.type == Card.TypeTrick then
                    goto continue
                elseif table.contains(player:getTableMark("soul_shock-phase"), "2") and card.trueName == "slash" then
                    goto continue
                end
                table.insertIfNeed(names, name)
                ::continue::
            end
            return UI.CardNameBox {
                choices = names
            }
        end,
        view_as = function(self, player, cards)
            if #cards ~= 1 then
                return
            end
            if not self.interaction.data then
                return
            end
            local card = Fk:getCardById(cards[1])
            local result = Fk:cloneCard(self.interaction.data)
            if card.trueName == "slash" and result.type ~= Card.TypeTrick then
                return
            end
            if card.type == Card.TypeTrick and result.trueName ~= "slash" then
                return
            end
            result:addSubcard(card)
            return result
        end,
        before_use = function(self, player, use)
            if use.card.trueName == "slash" then
                use.unoffsetableList = player.room:getAllPlayers()
            end
        end,
        after_use = function(self, player, use)
            local records = player:getTableMark("soul_shock-phase")
            if use.card.trueName == "slash" then
                table.insertIfNeed(records, "2")
            else
                table.insertIfNeed(records, "1")
            end
            player.room:setPlayerMark(player, "soul_shock-phase", records)
        end,
        enabled_at_play = function(self, player)
            return player.phase == Player.Play and #player:getTableMark("soul_shock-phase") < 2
        end,
        enabled_at_response = Util.FalseFunc,
    })

    extension:loadSkillSkels { reverberation, soul_shock }
    hy_merlin_prismriver:addSkills { "reverberation", "soul_shock" }

    Fk:loadTranslationTable {
        ["hy_merlin_prismriver"] = "梅露兰",
        ["#hy_merlin_prismriver"] = "躁狂管乐手",
        ["illustrator:hy_merlin_prismriver"] = "かこね",
        ["designer:hy_merlin_prismriver"] = "黑曜人形",
        ["cv:hy_merlin_prismriver"] = "",

        ["reverberation"] = "环号",
        [":reverberation"] = "每轮开始时，你可以视为使用你上一轮造成伤害的基本牌与普通锦囊牌各至多一张（每多目标牌名限一次），此牌造成的伤害改为失去体力。",
        ["reverberation_prompt"] = "环号：你可以视为使用一张牌",

        ["soul_shock"] = "荡灵",
        [":soul_shock"] = "出牌阶段各限一次，你可以：1.将一张【杀】当作一张单目标伤害类普通锦囊牌使用；2.将一张锦囊牌当作不可被响应的【杀】使用。",
    }
end
